package com.heima.Aop;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Aspect
@Component
public class TestAop {

    @Pointcut("@annotation(com.heima.Anno.TestAnno)")
    public void pt(){

    }


    @Around("pt()")
    public Object testTime(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        Object proceed = pjp.proceed();

        long end = System.currentTimeMillis();
        long time = TimeUnit.MICROSECONDS.toSeconds(end - start);
        System.out.println("该接口执行时间为:"+time+"秒");
        return proceed;
    }
}
